package ControlLayer;

import java.sql.Date;
import java.util.ArrayList;

import DBLayer.*;
import ModelLayer.*;



public class CtrCustomer {
	
	DBCustomer dbCustomer;
	
	public CtrCustomer()
	{
		dbCustomer = new DBCustomer();
	}

	
	
	
	public ArrayList<Customer> getAllCustomer()
	{
		return dbCustomer.getAllCustomer();
	}
	
	
	
	public Customer findCustomer(int customerId) 
	{
		return dbCustomer.findCustomer(customerId);
	}	
	public Customer findCustomerByName(String name)
	{
		return dbCustomer.findByName(name);
	}
	
	
	public int deleteCustomer(int customerId)
	{
		return dbCustomer.deleteCustomer(customerId);
	}
	
	
	public int updateCustomer(int customerId, String name, String surname, String address, String email, String phone, String company)
	{
		Customer customer = new Customer(customerId, name, surname, address, email, phone, company);
		return dbCustomer.updateCustomer(customer);
	}
	
	public void insertNewCustomer(int customerId , String name , String surname, String address , String email , String phone , String company)
    {    
	

      Customer customerObj = new Customer();
      customerObj.setCustomerId(customerId);
     
      customerObj.setCustomerName(name);
      customerObj.setCustomerSurname(surname);
      customerObj.setCustoemrAddress(address);
      customerObj.setCustomerEmail(email);
      customerObj.setCustomerPhone(phone);
      customerObj.setCustomerCompany(company);

         try{
          DbConnection.startTransaction();
          
          DBCustomer dbCustomer = new DBCustomer();
          dbCustomer.insertCustomer(customerObj);
          DbConnection.commitTransaction();
         }
         catch(Exception e)
         {
             DbConnection.rollbackTransaction();
         }
    }
	
}
